Semantic Analysis and Expansion

These two interlinked phases have the following purpose:

<#2750#>Semantic analysis<#2750#>
performs name and type resolution, decorates the AST with various semantic attributes, and as by-product performs all static legality checks on the program.

<#2751#>The expander<#2751#>
modifies the AST in order to simplify its translation into the GCC tree. Most of the expander activity results in the construction of additional AST fragments. Given that code generation requires that such fragments carry all semantic attributes, every expansion activity must be followed by additional semantic processing on the generated tree. This recursive structure is carried further: some predefined operations such as exponentiation are defined by means of a generic procedure. The expansion of the operation results in the generic instantiation (and corresponding analysis) of this generic procedure.

There is a further unusual recursive aspect to the structure of GNAT. The program library (described in greater detail below) does not hold any intermediate representation of compiled units. As a result, package declarations are analyzed whenever they appear in a context clause. Furthermore, if a generic unit, or an inlined unit <#459#>G<#459#>, is defined in a package <#460#>P<#460#>, then the instantiation or inlining of <#461#>G<#461#> in the current compilation requires that the body of <#462#>P<#462#> be analyzed as well. Thus the library manager, the parser, and the semantic analyzer can be activated from within semantic analysis (note the backward arrows in figure~#phases#463>).